#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

typedef struct Node
{
	char data;
	Node *next;
}*list;
list create(list head){
	if(head=NULL){
		head=(list)malloc(sizeof(struct Node));
		head->next=NULL;
	}
	list p=head;
	char x;
	scanf("%c",&x);
	while(x!=-1){
		getchar();
		list node=(list)malloc(sizeof(struct Node));
		node->data=x;
		node->next=p->next;
		p->next=node;
		p=node;
		scanf("%c",&x);
	}
	p->next=NULL;
	return head;
}
bool cmp(char B[],list A)
{
	list p=A->next;  //工作指针
	list now=p;//定位
	int i=0;
	while(i<strlen(B)&&p!=NULL)
	{
		if(B[i]==p->data)
		{
			i++;
			p=p->next;
		}
		else
		{
			i=0;
			now=now->next;
			p=now;
		}
		
	}
	if(i==strlen(B))return true; //完成匹配
	return false; //匹配到链尾也没成功
}

cmp(char b[],list a){
	list p=a->next;
	list now=p;
	int i=0;
	while(i<strlen(b)&&p!=NULL){
		if(b[i]==p->data){
			i++;
			p=p->next;
		}else{
			i=0;
			now=now->next;
			p=now;
		}
	}
	if(i==strlen(b)) return true;
	else return false;
}
void printlist(list head){
	list p=head;
	while(p){
		printf("%c->",p->data);
		p=p->next;
	}
}
int main(){
	list head=NULL;
	head=create(head);
	printlist(head);
    char a[3]={'a','b','c'};
	printf("%d",cmp(a,head));
    return 0;
}